package com.company;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

class MyTask extends TimerTask {
    long timer = 0;
    @Override
    public void run() {
        long now = (new Date()).getTime();
        if (this.timer == 0) {
            this.timer = now;
            System.out.println("run in" + now);
        } else {
            System.out.println("plus " + (now - this.timer));
            this.timer = now;
        }
        System.out.println("run---");
    }
}

public class JavaTimer {
    public static void main(String[] args) {
        Timer tm = new Timer();
        tm.schedule(new MyTask(), 1000, 2000);
    }
}
